<?php

use yii\db\Migration;

class m180320_085015_create_mechanic_settlement_subsidy extends Migration
{
    private function createDbs(){
        $dbs = [];
        $dbs_info =\Yii::$app->params['db'];
        foreach($dbs_info as $k=>$v){
            $dbs[$k] = \Yii::createObject($v);
        }
        return $dbs;
    }
    public function safeUp()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->createTable('{{%mechanic_settlement_subsidy}}',[
                'id' => $this->primaryKey()->notNull().' COMMENT \'自增id\'',
                'mechanic_settlement_id' => $this->integer()->defaultValue(0)->comment('结算id'),
                'money' => $this->decimal(10,2)->defaultValue(0)->comment('金额'),
                'remark' => $this->string(255)->defaultValue(null)->comment('备注'),
                'updated_at' => $this->integer()->defaultValue(0)->comment('修改时间'),
                'created_at' => $this->integer()->defaultValue(0)->comment('添加时间'),
            ]);
            $this->addCommentOnTable('{{%mechanic_settlement_subsidy}}','机构额外补助记录表');
            $this->addColumn('{{%mechanic_settlement}}', 'additional_money', $this->decimal(10,2)->defaultValue(0)->comment('额外奖励惩罚'));
        }
    }

    public function safeDown()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->dropTable('{{%mechanic_settlement_subsidy}}');
        }
    }
}
